package swingSection;

import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class DeleteDialog extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane2 = new JPanel();
	private JLabel nameLabel = new JLabel();
	private JTextField nameText = new JTextField();
	private JButton okButton = new JButton();
	private JButton cancelButton = new JButton();
	private int result=1;

	/**
	 * This is the default constructor
	 */
	public DeleteDialog() {
		super();
		this.getRootPane().setDefaultButton(okButton);
		this.setLayout(null);
		this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
		this.setModal(true);
		this.setBounds(new Rectangle(50, 50, 140, 260));
		jContentPane2.setBounds(new Rectangle(50, 50, 140, 260));
		this.add(jContentPane2);
		this.setTitle("Delete User");
		nameLabel.setBounds(new Rectangle(10, 10, 130, 25));
		nameLabel.setText("Username:");
		this.add(nameLabel);
		nameText.setBounds(new Rectangle(10, 45, 100, 25));
		nameText.setText("");
		this.add(nameText);
		okButton.setBounds(new Rectangle(10, 150, 100, 25));
		okButton.setText("OK");
		okButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int res=JOptionPane.showConfirmDialog(new DeleteDialog(), "Are you sure you want to delete this user?","Delete",JOptionPane.YES_NO_OPTION);
				if (res==JOptionPane.YES_OPTION){
				result = 0;
				}
				setVisible(false);
			}

		});
		this.add(okButton);
		cancelButton.setBounds(new Rectangle(10, 185, 100, 25));
		cancelButton.setText("Cancel");
		cancelButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				result = 1;
				setVisible(false);
			}

		});
		this.add(cancelButton);
	}

	public int showDialog() {
		nameText.setText("");
		this.setVisible(true);
		return result;
	}

	public String getUserName() {
		return nameText.getText();
	}

	public int getResult() {
		return result;
	}

}
